//
//  BHomeController.m
//  Ten
//
//  Created by anfuer on 2018/11/14.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "BHomeController.h"
#import "MsgCell.h"
#import "SDCycleScrollView.h"
#import "YMCitySelect.h"
@interface BHomeController ()<SDCycleScrollViewDelegate,YMCitySelectDelegate,UIScrollViewDelegate>
{
    SDCycleScrollView *cycleScrollView;
     NSArray*banner;
}
@property (weak, nonatomic) IBOutlet UITableView *tbv;
@property (weak, nonatomic) IBOutlet UIView *bannerBack;

@end

@implementation BHomeController
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:NO];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}

-(void)ym_ymCitySelectCityName:(NSString *)cityName{
    
//    [_cityBtno setTitle:cityName forState:UIControlStateNormal];
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    _tbv.separatorColor=[UIColor clearColor];
    if (!cycleScrollView) {
        cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, DEVW, 230) delegate:self placeholderImage:WXGImage(@"banner占位")];
        [_bannerBack addSubview:cycleScrollView];
        cycleScrollView.autoScrollTimeInterval=5;
  
    }
    
    if (@available(iOS 11.0, *)){
        _tbv.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        _tbv.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
    }else
    {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self loaddata];
}
-(void)loaddata
{
    [FuncPublic getData:self parameters:@{@"page":@"1"} RequestUrl:Xindex success:^(NSDictionary *acountInfo) {
        [_tbv.mj_header endRefreshing];
        [_tbv.mj_footer endRefreshing];
        banner =acountInfo[@"banner"];
        NSMutableArray*tempmary=[NSMutableArray array];
        [banner enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSDictionary*dic=obj;
            [tempmary addObject:dic[@"image"]];
        }];
        cycleScrollView.imageURLStringsGroup=tempmary;
        
     
    }];
    
}
/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    [MyUtils OpenHtmlforStr:WXGStr(banner[index][@"url"])];
}
#pragma mark 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  12;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    static NSString *ID = @"MsgCell";
    MsgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}


#pragma mark 设置每行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 115;
}
#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"BHome" bundle:nil];
    UIViewController*secondViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"Lookjianli"];
    [self.navigationController pushViewController:secondViewController animated:YES];
    

}



@end
